package com.example.myhelloworld.client;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class TestCreaterExercise extends ExerciseClass {

	// each element in vpan should be a HorizontalPanel, with fields for constructing an exercise.  
	VerticalPanel vpan; 
	
	public TestCreaterExercise(String uName, String settings,
			GreetingServiceAsync GSA) {
		super(uName, settings, GSA);
		
		//started 21.25
		DockPanel dPane = new DockPanel();
		selfPanel = dPane; 
		produceResultButton = new Button("Create Test! ");
		
		dPane.addStyleName("ExerciseBasic");
		
		 vpan = new VerticalPanel();
		HorizontalPanel row = new HorizontalPanel();
		HTML exText = new HTML("Enter exercise Text");
		TextBox exSettings = new TextBox();
		exSettings.setText("String exName, String produceString, String availableTo, String option");
		row.add(exText);
		row.add(exSettings);
		vpan.add(row);
		Button moreExercises = new Button("(+)");
		
		dPane.add(vpan, DockPanel.NORTH);
		dPane.add(produceResultButton, DockPanel.SOUTH);
		dPane.add(moreExercises, DockPanel.SOUTH);
		
//		 a test should look something like this one, perhaps this one should return a comma-separated string looking like the arguments to this one..: 
//		exArr[6] = new ExerciseObject("Test", "TestExercise", "student, teacher", "plusMinusDivTimes:Plus,plusMinusDivTimes:Div");
	}

	@Override
	public void draw() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String pushresult() {
		for (int i = 0; i<vpan.getWidgetCount();i++){
			String ArgumentText = ((TextBox)((HorizontalPanel)vpan.getWidget(0)).getWidget(1)).getText();
			gsa.addExercise(ArgumentText, new AsyncCallback<String>(){

				public void onFailure(Throwable caught) {
				}
				public void onSuccess(String result) {
				}});
		}

		
		return "";
	}

}
